package com.winbomb.kingcard.base.anim;

public abstract class Animation {

	/** 动画持续时间 */
	float duration;

	/** 消耗的时间 */
	float timeCost;

	/** 总共有多少个画面 */
	int frameCount;

	/** 现在是第几个画面 */
	int currFrame = 0;

	/** 画面切换的时间间隔 */
	float frameInterval = 100;

	/** 当前帧与上一帧之间的时间间隔 */
	private float interval = 0;

	public void setDuration(float duration) {
		this.duration = duration;
	}

	public float getCostTime() {
		return this.timeCost;
	}

	public boolean hasFinished() {
		return timeCost >= duration;
	}

	public int getFrameCount() {
		return frameCount;
	}

	public void setFrameCount(int frameCount) {
		this.frameCount = frameCount;
	}

	public int getCurrFrame() {
		return currFrame;
	}

	public void setCurrFrame(int currFrame) {
		this.currFrame = currFrame;
	}

	public float getFrameInterval() {
		return frameInterval;
	}

	public void setFrameInterval(float frameInterval) {
		this.frameInterval = frameInterval;
	}

	public float getDuration() {
		return duration;
	}

	public void step(float dt) {
		timeCost += dt;
		interval += dt;
		if (interval >= frameInterval) {
			currFrame++;
			interval -= frameInterval;
		}

		currFrame = (currFrame >= frameCount) ? 0 : currFrame;

		refresh(dt);
	}

	public void reset() {
		this.currFrame = 0;
		this.timeCost = 0;
	}

	public abstract void refresh(float dt);

}
